package xiegd.study.localTime;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/3/24 9:49
 */
public class GetDateTIme {

    /**
     * 返回当前天的开始时间、结束时间
     */
    public static List<String> getToday(){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 获取当天日期
        LocalDate now = LocalDate.now();
        String startDay = now.format(formatter);
        String endDay = now.format(formatter);
        List<String> dayList = Arrays.asList(startDay, endDay);
        return  dayList;
    }

    /**
     * 返回当前周的开始时间、结束时间
     */
    public static List<String> getWeek(){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 获取当天日期
        LocalDate now = LocalDate.now();
        LocalDate monday = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        String startDay = monday.format(formatter);
        // 周日
        LocalDate sunday = now.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        String endDay = sunday.format(formatter);
        List<String> weekList = Arrays.asList(startDay, endDay);
        return weekList;
    }
    /**
     * 返回当前月的开始时间、结束时间
     */
    public static List<String> getMoon(){
        LocalDate now = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 本月1号
        LocalDate firstDayOfMonth = now.with(TemporalAdjusters.firstDayOfMonth());
        String startDay = firstDayOfMonth.format(formatter);

        // 本月最后一天
        LocalDate lastDayOfMonth = now.with(TemporalAdjusters.lastDayOfMonth());
        String endDay = lastDayOfMonth.format(formatter);
        List<String> moonList = Arrays.asList(startDay, endDay);
        return moonList;
    }
    /**
     * 返回当前年的开始时间、结束时间
     */
    public static List<String> getYearList(){
        LocalDate now = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 本月1号
        LocalDate  firstDayOfYear= now.with(TemporalAdjusters.firstDayOfYear());
        String startDay = firstDayOfYear.format(formatter);

        // 本月最后一天
        LocalDate lastDayOfYear = now.with(TemporalAdjusters.lastDayOfYear());
        String endDay = lastDayOfYear.format(formatter);
        List<String> yearList = Arrays.asList(startDay, endDay);
        return yearList;
    }
}
